/*
 * Algorithem.h
 *
 *  Created on: Dec 12, 2009
 *      Author: ssperetz
 */

#include "SenetBoard.h"
#include "SmartSenetBoard.h"
#include "_039944228_052326816.h"
#include "Definitions.h"
#include "Heuristic.h"

#ifndef ALGORITHEM_H_
#define ALGORITHEM_H_

class Algorithem {
public:

	static int startExpectiMax(SmartSenetBoard& smartSenetBoard,
			GameTimer& my_timer, Heuristic* h);
	static int startStarOne(SmartSenetBoard& smartSenetBoard,
			GameTimer& my_timer, Heuristic* h);

	static int startIteritiveStarOne(SmartSenetBoard& smartSenetBoard,
			GameTimer& my_timer, Heuristic* h);

	static int startStarTwo(SmartSenetBoard& smartSenetBoard,
			GameTimer& my_timer, Heuristic* h);

	static int startIteritiveStarTwo(SmartSenetBoard& smartSenetBoard,
			GameTimer& my_timer, Heuristic* h);

	// isChanceState should be initialized with false and isFirst should be init with true;
	static double expectimax(SmartSenetBoard& curBoard,
			const Definitions::PlayerColor p, bool isChanceState, int depth,
			bool isFirst, GameTimer& my_timer);
	static double starOne(SmartSenetBoard& curBoard,
			const Definitions::PlayerColor p, bool isChanceState, int depth,
			bool isFirst, GameTimer& my_timer, double alpha, double beta);

	static int counter;
	static int counterIteritive;
	static int curBestDepth;

private:

	static double starTwo(SmartSenetBoard& curBoard,
		const Definitions::PlayerColor myColor, bool isChanceState, int depth,
		bool isFirst, GameTimer& my_timer, double alpha, double beta);

	static double getStarTwoBound(SmartSenetBoard& curBoard,
		const Definitions::PlayerColor myColor, bool isChanceState, int depth,
		bool isFirst, GameTimer& my_timer, double alpha, double beta);

	static void undo(SmartSenetBoard & curBoard,
			SenetChanceState & senetChanceState, int & posAfter,
			int & posBefore, const Definitions::PlayerColor & curColor,
			bool & isPeaceOnReBirthPlace, int & numOnSticks);
	static void prepareUndo(SenetMove & nextMove,
			int & posBefore,
			int & posAfter, int & numOnSticks, SmartSenetBoard & curBoard,
			bool & isPeaceOnReBirthPlace);
	static int choose(int x, int y);
	static int factorial(int a);
	static double heuristic(SmartSenetBoard & curBoard,
			const Definitions::PlayerColor myColor);

	static void setMaxMinHeuristics(const SmartSenetBoard & curBoard);
	static double getBoradHeuristic(const SmartSenetBoard & curBoard,
			const Definitions::PlayerColor myColor);

	static void reorderingNodes(vector<SenetMove>& nextLegalMoves,
			SmartSenetBoard& smartSenetBoard, int numOnSticks, const Definitions::PlayerColor myColor, const Definitions::PlayerColor curColor);


	static SenetMove& getBestMove(vector<SenetMove>& nextLegalMoves,
		SmartSenetBoard& curBoard, int numOnSticks,
		const Definitions::PlayerColor myColor,
		const Definitions::PlayerColor curColor);

	static void printBorad(SmartSenetBoard& board);

	static int selectedSquare;
	static int numOfSticks;
	static double coefficientProbabilty; // belongs to chanceState calculation 0.5 ^ numOfSticks

	static Heuristic* curHeuristic;

	

	//TODO to delete
	static bool flag;
	static int curException;
	

	//	static double maxHeuristic;
	//	static double minHeuristic;

	// i add this function


};

#endif /* ALGORITHEM_H_ */
